/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.model;
/**
 * 说明：
 * 供应商管理model
 * @Author：黄盛强
 * @Date：2012-03-20
 */
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TEmployee;
import com.ruipengkj.bean.TSupplier;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.service.TEmployeeService;

public class DataSupplierModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	
	private TEmployeeService tEmployeeService;
	
	public DataSupplierModel(){
		tEmployeeService = BuildSpringApplication.getInstance().getTEmployeeServiceImpl();
		columns.add("供应商编号");
		columns.add("供应商名称");
		columns.add("地址");
		columns.add("联系人");
		columns.add("手机");
		columns.add("固定电话");
		columns.add("备注");
//		columns.add("提供商评价");
		columns.add("创建人");
		columns.add("创建时间");
		columns.add("是否有效");
	}
	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	

	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	
	
	
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}


	public void setRowData(List<TSupplier> tSupplierList) {
		rowdatas.clear();
		if(tSupplierList != null && tSupplierList.size() != 0){
			for(int i = 0;i < tSupplierList.size();i++){
				TSupplier tSupplier = tSupplierList.get(i);
				List<Object> row=new Vector<Object>();
				row.add(tSupplier.getSupplierID());
				row.add(tSupplier.getName());
				row.add(tSupplier.getAddress());
				row.add(tSupplier.getContact());
				row.add(tSupplier.getMobile());
				row.add(tSupplier.getPhone());
				row.add(tSupplier.getRemark());
//				row.add(tSupplier.getPriority());
//				row.add(tSupplier.getOperator());
				if (tSupplier.getOperator() != null) {
				try {
					TEmployee tEmployee = tEmployeeService.getNameByIdService(tSupplier.getOperator());
					if (tEmployee != null && tEmployee.getName() != null)
						row.add(tEmployee.getName());
					else
						row.add("");
				} catch (Exception e) {
					e.printStackTrace();
				}
				} else {
					row.add("");
				}
				row.add(tSupplier.getHappenTime());
				if(tSupplier.isIsValid()){
					row.add("有效");
				}else{
					row.add("无效");
				}
				rowdatas.add(row);
			}
		}
	}
	
	public void clear(){
		rowdatas.clear();
	}
}
